export default{
  namespaced: true,
  state:{
    id:null,
    name:'',
  },
  mutations:{
    setId(state,dianpu){
      state.id = dianpu.id
      state.name = dianpu.name
      let dianpuString = JSON.stringify(dianpu)
      sessionStorage.setItem('dianpu',dianpuString)
    },
  },
  actions:{
    getId(context){
      return new Promise((resolve) => {
        let dianpu = sessionStorage.getItem('dianpu')
        if(dianpu){
          let dianpuObj = JSON.parse(dianpu)
          context.state.id = dianpuObj.id
          context.state.name = dianpuObj.name
          resolve(dianpuObj)
        }else{
          resolve('')
        }
      });
    }
  }
}